/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Search structure for locating entries by String - header.
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef _GIMNETAP_STRMAP_H_
#define _GIMNETAP_STRMAP_H_

//#include <pthread.h>

/** Single entry stored in Str map.
 */
typedef struct SStrMapEntry
{
  char *key;                 ///< Key
  const void *entry;         ///< Stored data.
  struct SStrMapEntry *prev; ///< Pointer to prev
  struct SStrMapEntry *next; ///< Pointer to next
} TStrMapEntry;

/** Bin container. Contains single entryarray.
 */
typedef struct SStrMapEntryBin
{
  TStrMapEntry *first;  ///< Array of entries begins here
  unsigned int entryCount; ///< Number of entries in array.
} TStrMapEntryBin;


/** StrMap container entry.
 */
typedef struct SStrMap
{
  unsigned int hashBinCount; ///< Number of HashBins on this container.
  TStrMapEntryBin *strMapEntryBins; ///< Array of entryBins
  
} TStrMap;

/** Structure used when enumerating all entries.
 */
typedef struct SStrMapEntryIterator
{
  unsigned int bin; ///< Current bin.
  TStrMapEntry *entry; ///< Current entry.
} TStrMapEntryIterator;

// public
TStrMap *strMapCreate();
int strMapInit( TStrMap *im, 
               const unsigned int aHashBinCount);
void strMapDeinit( TStrMap *im );
void strMapDestroy( TStrMap *im );

void strMapClear(TStrMap *im);
int strMapAddEntry(TStrMap *im, const char * const key, const void *aEntry);
int strMapDeleteEntry(TStrMap *im, const char * const key);
const TStrMapEntry *strMapGetEntry(TStrMap *im, const char * const key);
void strMapGetNextEntryIterator(TStrMap *im, TStrMapEntryIterator *aIter);
const TStrMapEntry *strMapGetNextEntry(TStrMap *im, TStrMapEntryIterator *aIter);

#endif
